<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    let demo = {
        template: `
                    <div>
                       {{msg}}
                    </div>`,
        data () {
            return {
                msg: 'hello World'
            }
        },
        methods: {
            sayHello () {
                console.log('Hi~');
            }
        }
    }
    let vm = {
        components: { demo },
        data () {
            return {
                count: 0
            }
        },
        template: `
                    <div>
                        <div>
                            {{count}}
                        </div>
                        <demo ref="demo"></demo>
                    </div>
                    `,
        created () {
            let c = this.$refs.demo
            console.log(c);
        },
        mounted () {
            let c = this.$refs.demo
            console.log(c)
            // ref通常是用来获取组件的对象
            // 从而可以在父组件中，调用子组件的属性（data）和方法（methods）
            console.log(this.$refs.demo.msg);
            this.$refs.demo.sayHello()
        }
    }
    Vue.createApp(vm).mount('#app')
</script>

</html>